import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _class;

import React, { PureComponent } from 'react';
import { Table, Tag, Popconfirm } from 'antd';
import { Bind } from 'lodash-decorators';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { enableRender, operatorRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
import { VERSION_IS_OP } from 'utils/config';
/**
 * 短信配置数据展示列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onChange - 分页查询
 * @reactProps {Boolean} loading - 数据加载完成标记
 * @reactProps {Array} dataSource - Table数据源
 * @reactProps {Object} pagination - 分页器
 * @reactProps {Number} pagination.current - 当前页码
 * @reactProps {Number} pagination.pageSize - 分页大小
 * @reactProps {Number} pagination.total - 数据总量
 * @return React.element
 */

var ListTable = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ListTable, _PureComponent);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "handleEdit",
    value: // constructor(props) {
    //   super(props);
    //   this.state = {
    //     isCopy: false,
    //   };
    // }
    // 编辑
    function handleEdit(record) {
      var onGetRecord = this.props.onGetRecord;
      onGetRecord(record);
    }
  }, {
    key: "handleCopy",
    value: function handleCopy(record) {
      var onCopy = this.props.onCopy;
      onCopy(record);
    }
  }, {
    key: "handleDelete",
    value: function handleDelete(record) {
      var onDelete = this.props.onDelete;
      onDelete(record);
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          smsData = _this$props.smsData,
          loading = _this$props.loading,
          pagination = _this$props.pagination,
          _onChange = _this$props.onChange,
          tenantRoleLevel = _this$props.tenantRoleLevel,
          path = _this$props.path;
      var columns = [!tenantRoleLevel && {
        title: intl.get('cmsg.smsConfig.model.smsConfig.tenant').d('租户'),
        dataIndex: 'tenantName',
        width: 150
      }, {
        title: intl.get('cmsg.common.view.accountCode').d('账户代码'),
        dataIndex: 'serverCode',
        width: 150
      }, {
        title: intl.get('cmsg.common.view.accountName').d('账户名称'),
        dataIndex: 'serverName',
        width: 150
      }, {
        title: intl.get('cmsg.smsConfig.model.smsConfig.serverTypeCode').d('服务类型'),
        dataIndex: 'serverTypeMeaning',
        width: 150
      }, {
        title: intl.get('cmsg.smsConfig.model.smsConfig.signName').d('短信签名'),
        dataIndex: 'signName'
      }, tenantRoleLevel && !VERSION_IS_OP && {
        title: intl.get('cmsg.common.view.source').d('来源'),
        width: 120,
        dataIndex: 'tenantId',
        render: function render(_, record) {
          var tenantId = _this.props.tenantId;
          return tenantId.toString() === record.tenantId.toString() ? /*#__PURE__*/React.createElement(Tag, {
            color: "green"
          }, intl.get('cpaas.common.custom').d('自定义')) : /*#__PURE__*/React.createElement(Tag, {
            color: "orange"
          }, intl.get('cpaas.common.predefined').d('预定义'));
        }
      }, {
        title: intl.get('cpaas.common.status').d('状态'),
        dataIndex: 'enabledFlag',
        width: 100,
        render: enableRender
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 150,
        key: 'error',
        render: function render(val, record) {
          var operators = [];
          var tenantId = _this.props.tenantId;

          if (tenantId.toString() === record.tenantId.toString() || !tenantRoleLevel) {
            operators.push({
              key: 'edit',
              ele: /*#__PURE__*/React.createElement(ButtonPermission, {
                type: "text",
                permissionList: [{
                  code: "".concat(path, ".button.edit"),
                  type: 'button',
                  meaning: '短信配置-编辑'
                }],
                onClick: function onClick() {
                  _this.handleEdit(record);
                }
              }, intl.get('cpaas.common.button.edit').d('编辑')),
              len: 2,
              title: intl.get('cpaas.common.button.edit').d('编辑')
            });
          }

          if (tenantId.toString() !== record.tenantId.toString() && tenantRoleLevel && !VERSION_IS_OP) {
            operators.push({
              key: 'copy',
              ele: /*#__PURE__*/React.createElement("a", {
                onClick: function onClick() {
                  _this.handleCopy(record);
                }
              }, intl.get('cpaas.common.button.copy').d('复制')),
              len: 2,
              title: intl.get('cpaas.common.button.copy').d('复制')
            });
          }

          if (tenantId.toString() === record.tenantId.toString() && tenantRoleLevel && !VERSION_IS_OP) {
            operators.push({
              key: 'delete',
              ele: /*#__PURE__*/React.createElement(Popconfirm, {
                title: intl.get("cmsg.smsConfig.view.message.title.confirmDelete").d('确定删除该数据吗？'),
                onConfirm: function onConfirm() {
                  return _this.handleDelete(record);
                },
                style: {
                  textAlign: 'center'
                }
              }, /*#__PURE__*/React.createElement("a", null, intl.get('cpaas.common.button.delete').d('删除'))),
              len: 2,
              title: intl.get('cpaas.common.button.delete').d('删除')
            });
          }

          return operatorRender(operators);
        }
      }].filter(Boolean);
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "serverId",
        dataSource: smsData.content || [],
        loading: loading,
        pagination: pagination,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        onChange: function onChange(page) {
          return _onChange(page);
        }
      }));
    }
  }]);

  return ListTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleEdit", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleEdit"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleCopy", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleCopy"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleDelete", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "handleDelete"), _class.prototype)), _class));
export { ListTable as default };